 readonly="readonly"<template>
  <div class="content-box">
    <nav-title title="语言能力" />
    <div class="line">
      <span class="important"></span>
      <div class="label">语言</div>
      <div class="value">
        <group label-width="5em">
          <popup-radio placeholder="请选择" readonly :options="lanList" v-model="language.rsLangCd"></popup-radio>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">证书名称</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="language.cDescr" readonly="readonly">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">获得日期</div>
      <div class="value">
        <group>
          <datetime value-text-align="left" readonly placeholder="请选择" v-model="language.cDate"></datetime>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">考试分数</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="language.cScore" readonly="readonly">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">掌握程度</div>
      <div class="value">
        <group label-width="5em">
          <popup-radio placeholder="请选择" readonly :options="techList" v-model="language.cLangLv"></popup-radio>
        </group>
      </div>
    </div>
    <div class="submit-btn" @click="save" v-if="showOr">
      保存
    </div>
    <div class="remove-btn" @click="remove" v-if="showOr">
      删除
    </div>
  </div>

</template>

<script>
import { Datetime, Group, PopupRadio } from 'vux'
import { savePLan,delLan,getDicItem } from '../../../api/api'
import { json2Form } from '../../../util/http'

export default {

  name: 'input-information',
  components: {
    Datetime, Group, PopupRadio
  },
  mounted(){
    //获取字典
    this.getDic();
    if(this.$route.params.cnta){
      this.language.cTransactionNbr = this.$route.params.cnta
    }
  },
  data() {
    return {
      language: {
        emplid: '10070226',
        cModStauts:'',
        cTransactionNbr:''
      },
      lanList: [],
      techList: [],
      showOr:true
    }
  },
  created() {
    this.getLang()
  },
  methods: {
    getDic(){
      //语言字典
      getDicItem({fileName: 'RS_LANG_CD'}).then(res=>{
        if(res && res.retCode === '000000'){
          for(let i=0; i<res.retData.length; i++){
            this.lanList.push({value: res.retData[i].xlatshortname,key: res.retData[i].fieldvalue});
          }
        }
      }).catch(res=>{

      });

      //掌握程度字典
      getDicItem({fileName: 'C_LANG_LV'}).then(res=>{
        if(res && res.retCode === '000000'){
          for(let i=0; i<res.retData.length; i++){
            this.techList.push({value: res.retData[i].xlatshortname,key: res.retData[i].fieldvalue});
          }
        }
      }).catch(res=>{

      });
    },
    save() {

      if(this.language.cModStauts == 'U'){
        this.language.cModStauts = 'U'
      }else{
        this.language.cModStauts = 'C'
      }

      // if(this.lan.length === 0){
      //   this.$vux.alert.show({
      //     title: '警告',
      //     content: '请选择语言'
      //   });
      //   return;
      // }

      // if(this.tech.length === 0){
      //   this.$vux.alert.show({
      //     title: '警告',
      //     content: '请选择掌握程度'
      //   });
      //   return;
      // }

      console.log(this.language)
      savePLan(json2Form(this.language)).then(res => {
        const that = this;
        //成功：000000
        if(res && res.retCode === '000000' ){
          //保存成功
          this.$vux.alert.show({
            title: '新城',
            content: '保存成功',
            onHide () {
              that.$router.push({
                name: 'userBase',
                params:{
                  cnta: that.language.cTransactionNbr
                }
              });
            }
          })

        }else{
          // 显示
          this.$vux.alert.show({
            title: '',
            content: res.retMsg
          })
        }
      }).catch (res=>{
        this.$vux.alert.show({
          title: '警告',
          content: '网络异常，请稍后重试'
        })
      })


    },
    remove() {
      const _this = this;
      _this.language.cModStauts = 'D'
      _this.$vux.confirm.show({
          // 组件除show外的属性
          title: '提示',
          content: '确定删除？',
          onCancel () {
          },
          onConfirm () {
            savePLan(json2Form(_this.language)).then(res=>{
              //成功：000000
              if(res && res.retCode === '000000' ){
                //删除成功
                _this.$vux.alert.show({
                  title: '新城',
                  content: '删除成功',
                  onHide () {
                    _this.$router.push({
                      name: 'userBase',
                      params:{
                        cnta: _this.language.cTransactionNbr
                      }
                    });
                  }
                })
              }else{
                // 显示
                _this.$vux.alert.show({
                  title: '',
                  content: res.retMsg
                })
              }

            })
            .catch(res=>{
              _this.$vux.alert.show({
                title: '',
                content: '网络异常，请稍后重试'
              })
            })

            
          }
        })
    },

    getLang() {
      if(this.$route.params.lang){
        this.language = this.$route.params.lang
        this.language.cTransactionNbr = this.$route.params.ctn
        this.language.cModStauts = this.$route.params.cModStauts
        if(!this.$route.params.ctn){
          this.showOr = false
        }
        console.log(this.language)
      }
    }
  }
}
</script>
<style type="text/scss" lang="scss" scoped>
@import "./personstyle";
</style>
